package com.example.controller;

import com.example.domain.ResponseResult;
import com.example.domain.entity.User;
import com.example.domain.entity.dto.UserInfoDto;
import com.example.exception.FloraException;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/getUserInfo/{id}")
    public ResponseResult getUserInfoById(@PathVariable Long id){
        return ResponseResult.okResult(userService.getUserInfoById(id));
    }

    @GetMapping("/getSellerById/{id}")
    public ResponseResult getSellerById(@PathVariable Long id){
        return ResponseResult.okResult(userService.getSellerById(id));
    }
    @GetMapping("/getSeller/{name}")
    public ResponseResult getSeller(@PathVariable String name){
        return ResponseResult.okResult(userService.getSeller(name));
    }
    /** 查看个人信息 */
    @GetMapping("/getUserInfo")
    public UserInfoDto getUserInfo(){
        return userService.getUserInfo();
    }

    /** 注册新用户 */
    @PostMapping("/register")
    public void registerUser(@RequestBody User user) throws FloraException {
        userService.registerUser(user);
    }

    /** 修改个人信息
     * 默认用户名不能更改，只能更改昵称（像QQ的账号密码一样）*/
    @PutMapping("/update")
    public void updateUserInfo(@RequestBody User user) throws FloraException {
        userService.updateUserInfo(user);
    }

    @PutMapping("/edit")
    public void editUserInfo(@RequestBody User user) throws FloraException {
        userService.editUserInfo(user);
    }

    /** 停用用户 */
    @PutMapping("block")
    public void blockUser(@RequestBody User user){
        userService.blockUser(user);
    }

}
